package a23_1;

import org.springframework.core.GenericTypeResolver;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 如何获取类上的泛型参数
 */
public class TestGenericType {
    public static void main(String[] args) {

        //1.JDK的API
        Type genericSuperclass = TeacherDao.class.getGenericSuperclass();  //获取泛型父类
        System.out.println(genericSuperclass);
        if (genericSuperclass instanceof ParameterizedType) { //具备泛型的父类才是ParameterizedType类型的
            Type[] actualTypeArguments = ((ParameterizedType) genericSuperclass).getActualTypeArguments();
            System.out.println(actualTypeArguments[0]);
        }


        System.out.println(">>>>>>>>>>>>>");

        //2.Spring的API
        Class<?> type = GenericTypeResolver.resolveTypeArgument(TeacherDao.class, BaseDao.class);  //默认是一个泛型，如果有多个泛型，请使用resolveTypeArguments
        System.out.println(type);
    }
}
